<?php
?>
<!doctype html>
<html>
    <head>
        <script>
           var ws = new WebSocket("ws://127.0.0.1:2000");
            ws.onopen = function(){
                console.log("握手成功");
            };
            ws.onmessage = function(e){
                console.log("message:" + e.data);
            };
            ws.onerror = function(){
                console.log("error");
            };
            
            if (ws.readyState === 1) {
                ws.send("李靖");
            }
        </script>
    </head>
    <body>
        参考：https://www.cnblogs.com/hustskyking/p/websocket-with-php.html
    </body>
</html>